package cn.gdpu.service.impl;

import java.util.List;

import cn.gdpu.dao.impl.UserDaoImpl;
import cn.gdpu.service.UserService;
import cn.gdpu.vo.Admin;
import cn.gdpu.vo.User;

public class UserServiceImpl extends BaseServiceImpl<User, Integer, UserDaoImpl> implements UserService<User, Integer> {
	




	public User getUserById(int id) {
		String hql = "from User u where u.id = '" + id + "'";
		List<User> users = getBaseDao().queryByHql(User.class, hql);
		if(users != null && users.size() != 0){
			return users.get(0);
		}else{
			return null;
		}
	}

	//根据用户名和密码拿到用户对象
	public User getUserByUsernameAndPassword(String username, String password) {
		String hql ="from User u where u.username = '" + username + "' and u.password = '" + password + "'";
		List<User> users = getBaseDao().queryByHql(User.class, hql);
		if(users != null && users.size()!= 0){
			return users.get(0);
		}else{
			return null;
		}
	}

	public User getUserByUsername(String username) {
		String hql ="from User u where u.username = '" + username + "'";
		List<User> users = getBaseDao().queryByHql(User.class, hql);
		if(users != null && users.size()!= 0){
			return users.get(0);
		}else{
			return null;
		}
	}

}
